//
// ***********************************************
// *    ___________   ___________  __      __    *
// *   |______  __/  /_____  ___/  \ \    / /    *
// *         / /          / /       \ \  / /     *
// *        / /          / /         \ \/ /      *
// *       / /          / /           \  /       *
// *      / /______    / /            / /        *
// *     /________/   /_/            /_/         *
// *                                             *
// ***********************************************
//
//   ViewController.m
//   InterviewDemo
//   
//   Created  by wanmeizty on 14/12/2019
//   Modified by Tiyon  qq 897574226  
//   Copyright © 2019 wanmeizty. All rights reserved.
//   
   

#import "ViewController.h"
#import "CategoryViewController.h"
#import "ThreadViewController.h"
#import "TableTestViewController.h"
#import "TestViewController.h"
#import "AdViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (copy,nonatomic) NSArray * dataList;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    UITableView * tableview = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.rowHeight = 40;
    [self.view addSubview:tableview];
    self.dataList = @[@"分类",@"线程",@"table",@"生命周期",@"广告"];
    
//    int n = 3;
//    NSMutableArray * array = [NSMutableArray array];
//    [self parathesesStr:@"" array:array left:n right:n];
//    NSLog(@"%@",array);
    // Do any additional setup after loading the view.
}

-(void)parathesesStr:(NSString *)str array:(NSMutableArray *)array left:(int)left right:(int)right{

    if (left == 0 && right == 0) {
        [array addObject:str];
    }
    if (right > left) {
        str = [NSString stringWithFormat:@"%@)",str];
        [self parathesesStr:str array:array left:left right:right-1];
    }
    if (left > 0) {
        str = [NSString stringWithFormat:@"%@(",str];
        [self parathesesStr:str array:array left:left - 1 right:right];
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    NSString * name = self.dataList[indexPath.row];
    cell.textLabel.text = name;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString * name = self.dataList[indexPath.row];
    if ([name isEqualToString:@"分类"]) {
        CategoryViewController * categoryvc = [[CategoryViewController alloc] init];
        [self.navigationController pushViewController:categoryvc animated:YES];
    }else if ([name isEqualToString:@"线程"]) {
        ThreadViewController * categoryvc = [[ThreadViewController alloc] init];
        [self.navigationController pushViewController:categoryvc animated:YES];
    }else if ([name isEqualToString:@"table"]) {
        TableTestViewController * categoryvc = [[TableTestViewController alloc] init];
        [self.navigationController pushViewController:categoryvc animated:YES];
    }else if ([name isEqualToString:@"生命周期"]) {
        TestViewController * categoryvc = [[TestViewController alloc] init];
        UIView * subview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        [categoryvc.view addSubview:subview];
        [self.navigationController pushViewController:categoryvc animated:YES];
    }else if ([name isEqualToString:@"广告"]) {
        AdViewController * categoryvc = [[AdViewController alloc] init];
        [self.navigationController pushViewController:categoryvc animated:YES];
    }
}

@end
